package com.dy.分类.哈希表和字符串._415_字符串相加;

public class Solution {
    public String addStrings(String num1, String num2) {
        int i = num1.length()-1;
        int j = num2.length()-1;
        int carry=0;
        StringBuilder sb = new StringBuilder("");
        while(i>=0 ||j>=0){
            int n1 = i>=0? num1.charAt(i)-'0':0;
            int n2 =j>=0? num2.charAt(j)-'0':0;
            i--;
            j--;
            int tmp = n1+n2+carry;
            carry = tmp/10;
            sb.append(tmp%10);
        }
        if(carry==1){
            sb.append(1);
        }
        return sb.reverse().toString();
    }
}
